package com.gtw.modules.api.controller;

import java.util.Map;

import com.baomidou.mybatisplus.plugins.Page;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.modules.api.service.TbPropertyService;
import com.gtw.modules.entity.TbProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 商品属性表
 *
 * @author wuye
 * @email www.baidu.com
 * @date 2018-02-01 10:46:46
 */
@RestController
@RequestMapping("/api/property")
public class TbPropertyController {

    @Autowired
    private TbPropertyService propertyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        Page<TbProperty> pageUtil = new Page<TbProperty>(query.getPage(), query.getLimit());
        Page<TbProperty> page = propertyService.queryPageList(pageUtil, query);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        TbProperty property = propertyService.queryObject(id);

        return R.ok().put("property", property);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbProperty property) {
        propertyService.save(property);

        return R.ok();
    }

}
